{% extends "base.html" %}
{% set active_page = 'worker_list' %}
{% block custom_head %}
    <script type="text/javascript" src="{{ root_path }}static/js/bootstrap-table.min.js"></script>
{% endblock %}
{% block page_nav %}
    <h2>Worker List</h2>
{% endblock %}
{% block body %}
    <div id="worker-list" class="row auto-refresh">
        <table data-classes="table" data-toggle="table">
            <thead>
            <tr>
                <th data-field="endpoint" data-sortable="true">Endpoint</th>
                <th data-field="cpu" data-sortable="true">CPU</th>
                <th data-field="mem" data-sortable="true">Mem</th>
                <th data-field="shared" data-sortable="true">Shared</th>
                <th>Update Time</th>
            </tr>
            </thead>
            <tbody>
            {%- if worker_metrics %}
                {%- for endpoint in worker_metrics %}
                    {% set metrics = worker_metrics[endpoint]['hardware'] %}
                    <tr>
                        <td><a href="{{ root_path }}worker/{{ endpoint }}">{{ endpoint }}</a></td>
                        <td>{{ '%0.2f' % metrics['cpu_used'] }} / {{ metrics['cpu_total'] }}</td>
                        <td>{{ metrics['memory_used'] | readable_size }} / {{ metrics['memory_total'] | readable_size }}</td>
                        <td>{{ metrics['cached_hold'] | readable_size }} / {{ metrics['cached_total'] | readable_size }}</td>
                        <td>{{ worker_metrics[endpoint]['update_time'] | format_ts }}</td>
                    </tr>
                {% endfor -%}
            {% else %}
                <tr>
                    <td colspan="8" style="font-style: italic; text-align: center">No workers attached.</td>
                </tr>
            {% endif -%}
            </tbody>
        </table>
    </div>
{% endblock %}
